// import Home from '@/views/Home'
// import Login from '@/views/Login'
// import Register from '@/views/Register'
// import Search from '@/views/Search'
// import Detail from '@/views/Detail'
// import AddCar from '@/views/AddCartSuccess'
// import ShopCart from '@/views/ShopCart'
// import Trade from '@/views/Trade'
// import Pay from '@/views/Pay'
// import PaySuccess from '@/views/PaySuccess'
// import Center from '@/views/Center'

const Home = () => import('@/views/Home')
const Login = () => import('@/views/Login')
const Register = () => import('@/views/Register')
const Search = () => import('@/views/Search')
const Detail = () => import('@/views/Detail')
const AddCar = () => import('@/views/AddCartSuccess')
const ShopCart = () => import('@/views/ShopCart')
const Trade = () => import('@/views/Trade')
const Pay = () => import('@/views/Pay')
const PaySuccess = () => import('@/views/PaySuccess')
const Center = () => import('@/views/Center')

const routes = [
  // 重定向到主页
  {
    path: '/',
    redirect: '/index'
  },
  // 主页
  {
    path: '/index',
    component: Home
  },
  // 登录
  {
    path: '/login',
    component: Login
  },
  // 注册
  {
    path: '/register',
    component: Register
  },
  // 搜索
  {
    path: '/search',
    component: Search
  },
  {
    path: '/detail/:id',
    component: Detail
  },
  {
    path: '/addCar',
    component: AddCar,
    beforeEnter: (to, form, next) => {
      if (form.path.slice(0, 7) !== '/detail') return next('/index')
      next()
    }
  },
  {
    path: '/car',
    component:
    ShopCart
  },
  {
    path: '/trade',
    component:
    Trade
  },
  {
    path: '/pay',
    component:
    Pay
  },
  {
    path: '/paySuccess',
    component:
    PaySuccess,
    beforeEnter:
      (to, form, next) => {
        if (form.path !== '/pay') return next('/')
        next()
      }
  },
  {
    path: '/center',
    component:
    Center
  },
  {
    path: '*',
    component:
    Home
  }
]

export default routes
